package com.fortune.controller;

import com.fortune.base.BaseAPIExcution;
import com.fortune.common.paging.PagingData;
import com.fortune.constants.Constants;
import com.fortune.dto.excution.DstoreInExcution;
import com.fortune.dto.in.ddataAnalysisDto.CommodityInventoryLedgerDto;
import com.fortune.dto.in.ddataAnalysisDto.DorderSummaryDto;
import com.fortune.entity.DUserInfo;
import com.fortune.enums.DstoreInEnum;
import com.fortune.service.DdataAnalysisService;
import com.fortune.vo.ddateAnalysis.ClientPro;
import com.fortune.vo.ddateAnalysis.ExpenseAccount;
import com.fortune.vo.ddateAnalysis.ProInStock;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2018/7/6 0006.
 */
@Api(value = "dataAnalysis", description = "经销商数据分析", tags = {"经销商数据分析"})
@RestController
@RequestMapping("dataAnalysis")
public class DdataAnalysisController {
    @Autowired
    private DdataAnalysisService service;

    @ApiOperation(value = "客户汇总列表", nickname = "dOrderSummaryList", notes = "", tags={ "@安童" })
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
            @ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
            @ApiImplicitParam(name="startTime", value="开始日期",paramType="query",dataType="date"),
            @ApiImplicitParam(name="endTime", value="结束日期",paramType="query",dataType="date"),
    })
    @GetMapping(value = "dOrderSummaryList",
            produces = { MediaType.APPLICATION_JSON_VALUE })
    public BaseAPIExcution<PagingData<ClientPro>> dOrderSummaryList(HttpServletRequest request, @ApiIgnore @Validated DorderSummaryDto dorderSummaryDto) {
        HttpSession session = request.getSession();
        DUserInfo dUserInfo = (DUserInfo) session.getAttribute(Constants.SESSION_D_USER);
        String did = dUserInfo.getdId();
        dorderSummaryDto.setPage((dorderSummaryDto.getPage()-1)*10);
        List<ClientPro> list = service.findOrderSummaryList(dorderSummaryDto,did);
        int count = service.findOrderSummaryListCount(did);
        PagingData<ClientPro> pagingData = new PagingData<ClientPro>();
        pagingData.setData(list);
        pagingData.setRecordsTotal(count);
        return new DstoreInExcution<PagingData<ClientPro>>(pagingData, DstoreInEnum.FIND_SUCCESS);
    }

    @ApiOperation(value = "商品库存汇总报表", nickname = "commodityInventorySummaryList", notes = "", tags={ "@安童" })
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
            @ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
    })
    @GetMapping(value = "commodityInventorySummaryList",
            produces = { MediaType.APPLICATION_JSON_VALUE })
    public BaseAPIExcution<PagingData<ProInStock>> commodityInventorySummaryList(HttpServletRequest request, @ApiIgnore @Validated DorderSummaryDto dorderSummaryDto) {
        HttpSession session = request.getSession();
        DUserInfo dUserInfo = (DUserInfo) session.getAttribute(Constants.SESSION_D_USER);
        String did = dUserInfo.getdId();
        dorderSummaryDto.setPage((dorderSummaryDto.getPage()-1)*10);
        List<ProInStock> list = service.findCommodityInventorySummaryList(dorderSummaryDto,did);
        int count = list.size();
        PagingData<ProInStock> pagingData = new PagingData<ProInStock>();
        pagingData.setData(list);
        pagingData.setRecordsTotal(count);
        return new DstoreInExcution<PagingData<ProInStock>>(pagingData, DstoreInEnum.FIND_SUCCESS);
    }

    @ApiOperation(value = "商品库存明细账", nickname = "commodityInventoryLedgerList", notes = "", tags={ "@安童" })
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
            @ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
            @ApiImplicitParam(name="storeId", value="仓库",paramType="query",dataType="string"),
            @ApiImplicitParam(name="proId", value="商品",paramType="query",dataType="string"),
    })
    @GetMapping(value = "commodityInventoryLedgerList",
            produces = { MediaType.APPLICATION_JSON_VALUE })
    public BaseAPIExcution<PagingData<ExpenseAccount>> commodityInventoryLedgerList(HttpServletRequest request, @ApiIgnore @Validated CommodityInventoryLedgerDto commodityInventoryLedgerDto) {
        HttpSession session = request.getSession();
        DUserInfo dUserInfo = (DUserInfo) session.getAttribute(Constants.SESSION_D_USER);
        String did = dUserInfo.getdId();
        commodityInventoryLedgerDto.setPage((commodityInventoryLedgerDto.getPage()-1)*10);
        List<ExpenseAccount> list = service.findCommodityInventoryLedgerList(commodityInventoryLedgerDto,did);
        int count = service.findCommodityInventoryLedgerListCount(commodityInventoryLedgerDto,did);
        PagingData<ExpenseAccount> pagingData = new PagingData<ExpenseAccount>();
        pagingData.setData(list);
        pagingData.setRecordsTotal(count);
        return new DstoreInExcution<PagingData<ExpenseAccount>>(pagingData, DstoreInEnum.FIND_SUCCESS);
    }
}
